package com.share.example.sbnfsj.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.JedisSentinelPool;

import java.util.LinkedHashSet;
import java.util.Set;

/*redis初始化*/
@Configuration
public class JedisSentinelPoolConfig {

    @Bean
    public JedisSentinelPool init() {
        String masterName = "master-1";
        Set<String> set = new LinkedHashSet<>();
        set.add("192.168.1.214:63791");
        set.add("192.168.1.214:63792");
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxIdle(5);
        config.setMinIdle(2);
        config.setMaxTotal(20);
        config.setMaxWaitMillis(2000);
        config.setTestOnBorrow(true);
        int timeOut = 2000;
        String password = null;
        int dbIndex = 12;
        JedisSentinelPool pool = new JedisSentinelPool(masterName, set, config, timeOut, null, dbIndex);
        return pool;
    }

}
